package pw.goyd.game.model;

import pw.goyd.game.constant.enumcard.CardSuit;
import pw.goyd.game.constant.enumcard.CardWeight;

/**
 * 扑克牌基础
 *
 * @author StanWind
 */

public class Card implements Comparable<Card> {
    //之前没增加枚举类型 Original

    public int suit;        //	花色 0-3
    public int weight;      //	权值 0-12

    /**
     * 拿到牌点数
     *
     * @return 牌面
     */
    public int getPointWeight() {
        return (getWeight() > 9 ? 9 : getWeight()) + 1;
    }

    public int getSuit() {
        return suit;
    }

    public void setSuit(int suit) {
        this.suit = suit;
    }

    public int getWeight() {
        return weight;
    }


    public void setWeight(int weight) {
        this.weight = weight;
    }

    @Override
    public int compareTo(Card o) {
        int compare = 0;

        int result = this.getWeight() - o.getWeight();
        if (result > 0) {
            compare = 1;
        } else if (result < 0) {
            compare = -1;
        } else if (result == 0) {
            result = this.getSuit() - o.getSuit();
            if (result > 0) {
                compare = 1;
            } else if (result < 0) {
                compare = -1;
            }
        }
        return compare;
    }

    @Override
    public String toString() {
        CardSuit cs = CardSuit.values()[suit];
        CardWeight cw = CardWeight.values()[weight];
        return "[" + cs + "," + cw + "]";
    }
}
